<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'老师列表'),
	//array('op'=>'edit','title'=>'添加老师'),	
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['on_areas like']='%'.$this->area_id.'%';
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','name','storeid','lesson_groupid','label','status','show','mid','headimg','on_areas','years','age','createtime','classid');
	$list=pdo_getslice('jy_kexie_worker',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['store']=pdo_get('jy_kexie_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']));
			$item['lesson']=pdo_get('jy_kexie_lesson_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['lesson_groupid']));
			$on_areas=str_array($item['on_areas']);
			$item['on_areas']='';
			foreach($on_areas as $ov){
				$areatitle=pdo_getcolumn('jy_kexie_area',array('uniacid'=>$_SESSION['uniacid'],'id'=>$ov),'title');
				$item['on_areas'] .=$areatitle.',';
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'name','title'=>'老师名称','type'=>'string'),
			array('name'=>'username','title'=>'用户名','type'=>'string'),
			array('name'=>'headimg','title'=>'老师头像','type'=>'image'),
			array('name'=>'on_areas','title'=>'所属区域','type'=>'string'),
			array('name'=>'lesson.title','title'=>'课程类型','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
		),'action'=>array(
		)),
	);
	$return['htmls']=$htmls;
	
	exi($return);
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的老师！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_kexie_worker',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}